using System;
using System.IO;
using GGEditor.API;
using GGEditor.API.Utility.Collections;
using GGEditor.Core.Plugins;

namespace GGEditor.Core.Commands
{
	//public class CommandManager : IUndoManager
	//{
	//    //private CommandManager() { }

	//    //private static ICommandManager instance =
	//    //    new CommandManager();

	//    //public static ICommandManager Instance
	//    //{
	//    //    get { return instance; }
	//    //}

	//    protected ICommandFactory GetCommandHost(string cmdPath)
	//    {
	//        string path = PluginPaths.GetNodePath(cmdPath);
	//        IPluginNode node = PluginManager.Instance.GetNode(path);
	//        if (node == null)
	//            return null;
	//        System.IO.FileStream f = new FileStream();
			
	//        return node.Object as ICommandFactory;
	//    }

	//    #region Implementation of ICommandFactoryManager

	//    public void DoCommand(string cmdPath)
	//    {
	//        ICommand command = GetCommand(cmdPath);
	//        if (command == null)
	//            return;
	//        ICommand undoCommand = command.Do(PluginManager.Instance);
	//        if (command.IsDestructive)
	//        {
	//            undoStack.Clear();
	//            redoStack.Clear();
	//        }
	//        else if (undoCommand != null)
	//            undoStack.Push(undoCommand);
	//    }

	//    private ICommand GetCommand(string cmdPath)
	//    {
	//        string path = PluginPaths.GetNodePath(cmdPath);
	//        string cmdName = PluginPaths.GetCommand(cmdPath);

	//        ICommandFactory commandHost = GetCommandHost(path);
	//        if (commandHost == null)
	//            return null;

	//        return commandHost.GetCommand(cmdName);
	//    }

	//    #endregion

	//    #region Implementation of IUndoManager

	//    private readonly IBoundedStack<ICommand> undoStack = new BoundedStack<ICommand>(10000);
	//    private readonly IBoundedStack<ICommand> redoStack = new BoundedStack<ICommand>(10000);

	//    public bool HasUndo
	//    {
	//        get { return !undoStack.Empty; }
	//    }

	//    public string UndoDescription
	//    {
	//        get
	//        {
	//            if (!HasUndo)
	//                return null;
	//            return undoStack.Peek().Description;
	//        }
	//    }

	//    public void Undo()
	//    {
	//        if (!HasUndo)
	//            return;
	//        ICommand cmd = undoStack.Pop();
	//        redoStack.Push(cmd.Do(PluginManager.Instance));
	//    }

	//    public bool HasRedo
	//    {
	//        get { return !redoStack.Empty; }
	//    }

	//    public string RedoDescription
	//    {
	//        get
	//        {
	//            if (!HasRedo)
	//                return null;
	//            return redoStack.Peek().Description;
	//        }
	//    }

	//    public void Redo()
	//    {
	//        if (!HasRedo)
	//            return;
	//        ICommand cmd = redoStack.Pop();
	//        undoStack.Push(cmd.Do(PluginManager.Instance));
	//    }

	//    #endregion
	//}
}